Repository navigation
fix(FOUR-34369): eager-load processRequest.process in optimized index… - #9157
Conversation
… query Register constrained with() for processRequest.process when the client requests that include on indexOptimizedBaseQuery. It was listed in handledIncludes but never applied, so the nested process was missing or lazy-loaded per row. https://processmaker.atlassian.net/browse/FOUR-34369
PR SummaryHigh Risk Overview Related fixes: raw token/request persistence now triggers Scout index sync after SQL updates; v1.1 task completion checks authorization before rejecting already-closed tasks; v1.1 optimized index passes managed-process visibility resolution into Reviewed by Cursor Bugbot for commit f43c706. Bugbot is set up for automated code reviews on this repo. Configure here. |
Raw UPDATEs in TokenPersistenceRawRepository bypass Eloquent save(), so Scout never ran when TOKEN_PERSISTENCE_RAW_ENABLED was on. Invoke ModelObserver::saved after token and process request raw updates so indexed search stays in sync on activate/complete. https://processmaker.atlassian.net/browse/FOUR-34369
indexOptimizedBaseQuery used process_request_token_id and uuid on TaskDraft, but drafts are keyed by task_id and the table has no uuid column. Align the include with TaskResource and show-fast: id, task_id, data. https://processmaker.atlassian.net/browse/FOUR-34369
With TASK_UPDATE_V1_1_ENABLED, PUT /api/1.1/tasks/{id} returned 422 for
another user's CLOSED tasks before Gate::authorize, leaking closed state.
Run the update policy first to match v1.0 and return 403 for unauthorized
callers on both open and closed tasks.
https://processmaker.atlassian.net/browse/FOUR-34369
Restore version and package-savedsearch constraint to match origin/develop, reverting local branch overrides. https://processmaker.atlassian.net/browse/FOUR-34369
…ager loads Extract helpers for include parsing and optimized with() building so indexOptimizedBaseQuery satisfies Sonar S3776 without changing query behavior. https://processmaker.atlassian.net/browse/FOUR-34369
…sion Eager-load task drafts without data on the optimized index and gate includeDraft on ProcessRequestTokenPolicy::view so view-all_requests cannot read other assignees' unsubmitted form data via include=draft.
…sion Eager-load task drafts without data on the optimized index and gate includeDraft on ProcessRequestTokenPolicy::view so view-all_requests cannot read other assignees' unsubmitted form data via include=draft. https://processmaker.atlassian.net/browse/FOUR-34369
…ctions ProcessRequestTokenPolicy::view needs user_id and process.manager_id; the optimized index and fast show omit them. Load missing attributes before gating draft.data, and eager-load manager_id when include=draft. https://processmaker.atlassian.net/browse/FOUR-34369
Omit draft payloads for list callers without task view rights; eager-load draft without data on the optimized index. Resolve manager checks from process.properties (not a DB column), avoid attaching process on draft-only includes, and hydrate partial tokens for assignee/self-service policy checks without leaking process config in list JSON. https://processmaker.atlassian.net/browse/FOUR-34369
Match ProcessRequestTokenPolicy::view when manager_id values in process properties are stored as strings. https://processmaker.atlassian.net/browse/FOUR-34369
Load manager IDs from a targeted properties query for draft gating instead of selecting properties onto the task process relation in showFast and the optimized task index. https://processmaker.atlassian.net/browse/FOUR-34369
There was a problem hiding this comment.
🔒 Agentic Security Review — 2 finding(s).
-
[MEDIUM]
ProcessMaker/Traits/TaskControllerIndexMethods.php:96— Draft payload redaction runs only when the include list contains the exact token "draft". On the default optimized task index, any other include path that eager-loads the draft relation (for example include=draft.processRequestToken or include=draft.media) is forwarded to Eloquent with(), loads the full TaskDraft row, and is emitted by Task::toArray via the model relation array because includeDraft() never runs. A caller who can list tasks but fails ProcessRequestTokenPolicy::view therefore receives another assignee's draft.data.- Impact: view-all_requests is a list permission, not task view. It is on the seeded Requesters group, and GET /api/1.0/tasks has no can:view middleware. applyForCurrentUser returns every task for that permission, while ProcessRequestTokenPolicy::view still withholds the task from non-assignees, non-managers, and non-self-service users. The new index test treats another assignee's in-progress form draft as data those callers must not receive. The nested-include bypass returns that JSON, including form fields the assignee has not submitted. Users without view-all_requests stay limited to their own and self-service tasks, and administrators are allowed to see drafts. With OPTIMIZED_TASKS_ENABLED=false the same hole is wider: indexBaseQuery always eager-loads an unconstrained draft, so an omitted include also embeds draft.data because includeDraft() is never called.
- Remediation: Apply the draft visibility filter whenever the draft relation is loaded, not only for the exact include token draft. Do not pass caller-supplied include paths that eager-load draft or draft.* around that filter; constrain or reject those paths. On the non-optimized index, stop unconditionally eager-loading the full draft row, or run the same redaction on any loaded draft before the task resource serializes relations. Keep the authorized re-query of data only after userCanViewTaskForDraft succeeds.
-
[MEDIUM]
ProcessMaker/Traits/TaskResourceIncludes.php:68— GET /api/1.0/tasks?include=draft now hydrates other assignees' TaskDraft rows on the default optimized index. When app.task_drafts_enabled is false, includeDraft calls $draft->delete() before the new userCanViewTaskForDraft check, so a view-all_requests user who can list tasks but fails ProcessRequestTokenPolicy::view deletes those drafts.- Impact: A normal authenticated user in the seeded Requesters role (view-all_requests only) can page through tasks they are not allowed to view and permanently delete other assignees' task_drafts rows, including the in-progress data JSON. TaskDraft uses Spatie HasMedia and model delete fires delete events (TaskDraftController relies on that); associated draft uploads are removed with the row. The same PR treats this caller as unauthorized for the draft payload and returns only id and task_id when drafts are enabled, so the disabled-draft branch is a cross-user integrity bypass of that boundary. The response is still 200 with draft:null.
- Remediation: Run userCanViewTaskForDraft (after ensureTokenAttributesForViewPolicy) before $draft->delete(). If the caller is unauthenticated or fails the view check, return draft:null and leave the row in place. Keep disabled-draft cleanup only for callers who pass ProcessRequestTokenPolicy::view. Add a test with task_drafts_enabled false asserting a view-all_requests caller does not remove another assignee's task_drafts row or its media.
Use TaskDraftIncludes for v1.1 preprocessInclude/fromTokenWithIncludes and load the draft relation only for exact include=draft, not draft.* tokens. https://processmaker.atlassian.net/browse/FOUR-34369
…ates Include the helper referenced by task index and task resources for parsing include=draft tokens, constrained eager loads, and draft.* filtering.
isDraftToken no longer uses str_contains('.draft'), which falsely blocked
includes such as processRequest.draftApproval. Treat draft only when the
token is draft, starts with draft., ends with .draft, or contains a .draft.
segment so nested draft paths stay gated without dropping unrelated includes.
https://processmaker.atlassian.net/browse/FOUR-34369
Apply draft visibility on any loaded draft payload (including draft.*-style includes), tighten optimized additionalIncludes filtering, and add legacy draft.media and disabled-draft media regression tests. https://processmaker.atlassian.net/browse/FOUR-34369
Redact nested drafts only under tokens lists, load tokens and drafts from the database with task_id constraints, and ignore planted id/draft objects in request_data. https://processmaker.atlassian.net/browse/FOUR-34369
Honor includesDraft on show (omit fast-path preloads without include, resolve when requested). Bind draft policy to persisted tokens and task_id-scoped rows; redact nested drafts only under tokens, not request_data. Tighten optimized index filters and add show/plant/disabled-draft regression tests. https://processmaker.atlassian.net/browse/FOUR-34369
Normalize draft segment detection so mixed-case includes cannot bypass eager-load filters or sanitize/redaction on nested token drafts. https://processmaker.atlassian.net/browse/FOUR-34369
Split resolveDraftPayloadForToken for Sonar S1142 and extract draftIdFromPayload to clear nested ternary S3358 without changing draft authorization behavior. https://processmaker.atlassian.net/browse/FOUR-34369
Passing null into applyProcessIndexPmql triggered a TypeError after the Sonar refactor added a string type hint; normalize pmql before the call. https://processmaker.atlassian.net/browse/FOUR-34369
…ForToken Merge token and draft early-exit guards for Sonar S1142 without changing draft authorization behavior. https://processmaker.atlassian.net/browse/FOUR-34369
… includes Nested draft includes (e.g. processRequest.tokens.draft) no longer eager-load, resolve, or delete the parent task draft when only nested paths are requested. Root draft.* includes still use constrained eager load with nested relations (draft.media). https://processmaker.atlassian.net/browse/FOUR-34369
… parsing Strip :* and :col from include paths so nested draft eager loads and sanitization apply to processRequest.tokens.draft:* variants; redact nested drafts defensively when serialized token trees contain draft payloads. https://processmaker.atlassian.net/browse/FOUR-3436fix(FOUR-34369): treat Laravel include column suffixes in draft token parsing Strip :* and :col from include paths so nested draft eager loads and sanitization apply to processRequest.tokens.draft:* variants; redact nested drafts defensively when serialized token trees contain draft payloads. https://processmaker.atlassian.net/browse/FOUR-343699
… disabled Nested draft redaction suppresses payload without deleting rows; root include=draft retains legacy delete-on-access for assignees. https://processmaker.atlassian.net/browse/FOUR-34369
…e drafts for managers When task drafts are disabled, process managers listing with processRequest.tokens.draft must not remove other assignees' task_drafts rows. https://processmaker.atlassian.net/browse/FOUR-34369
Avoid per-row token queries on optimized index when draft is included; prefetch nested token rows for redaction and cache process manager ids. https://processmaker.atlassian.net/browse/FOUR-34369
…o assignee Reject serialized token policy fields, require authoritative attrs on root resource, and avoid deleting assignee drafts when managers list with include=draft while drafts are disabled. https://processmaker.atlassian.net/browse/FOUR-34369
test(cache): enable metrics in ScreenCacheFactoryTest setUp refactor(FOUR-34369): reduce Sonar complexity in TaskResourceIncludes https://processmaker.atlassian.net/browse/FOUR-34369
|



… query
Register constrained with() for processRequest.process when the client requests that include on indexOptimizedBaseQuery. It was listed in handledIncludes but never applied, so the nested process was missing or lazy-loaded per row.
https://processmaker.atlassian.net/browse/FOUR-34369
ci:screen-builder:v3.8.43-branch-5932fbd7
ci:vue-form-elements:v0.65.11-branch-2c6a640